from fastapi import APIRouter, Request, FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles

class WebRoutes:
    def __init__(self, app: FastAPI, router: APIRouter):
        # print("WebRoutes __init__ ============================")
        self.app = app
        self.router = router
        self.docs_path = "template/swagger/index.html"
        self.index_path = "template/index.html"
        self.index_css_path = "template/styles.css"

    def setup(self):
        @self.router.get("")
        async def get_index(request: Request):
            # print("get_index ============================")
            return HTMLResponse(content=open(self.index_path).read())
        
        @self.router.get("/docs")
        async def get_docs(request: Request):
            # print("get_docs ============================")
            return HTMLResponse(content=open(self.index_path).read())
        

        # Serve static files from template directory
        self.app.mount("/static", StaticFiles(directory="template"), name="static")
        self.app.include_router(self.router, prefix="/html")
